package com.xlhj.mongodb.service.impl;

import com.xlhj.mongodb.dao.UserMongoDbDao;
import com.xlhj.mongodb.entity.SysUser;
import com.xlhj.mongodb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author liucaijing
 * @Date 2021/2/26 14:27
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMongoDbDao userMongoDbDao;

    @Override
    public SysUser selectUserById(Long id) {
        SysUser userInfo = userMongoDbDao.findById(id).get();
        return userInfo;
    }

    @Override
    public List<SysUser> selectAllUser() {
        return userMongoDbDao.findAll();
    }

    @Override
    public SysUser insertUser(SysUser user) {
        SysUser insertUser = userMongoDbDao.insert(user);
        return insertUser;
    }

    @Override
    public SysUser updateUser(SysUser user) {
        SysUser saveUser = userMongoDbDao.save(user);
        return saveUser;
    }

    @Override
    public void deleteUserById(Long id) {
        userMongoDbDao.deleteById(id);
    }
}
